package com.zyj.repairs.controller;

import java.util.List;

import com.zyj.common.annotation.Log;
import com.zyj.common.core.controller.BaseController;
import com.zyj.common.core.domain.AjaxResult;
import com.zyj.common.core.page.TableDataInfo;
import com.zyj.common.enums.BusinessType;
import com.zyj.common.utils.poi.ExcelUtil;
import com.zyj.supplier.domain.AsstesSupplier;
import com.zyj.supplier.service.IAsstesSupplierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 供应商Controller
 * 
 * @author ZhuYujie
 * @date 2022-05-13
 */
@Controller
@RequestMapping("/system/supplier")
public class AsstesSupplierController extends BaseController
{
    private String prefix = "assets/supplier";

    @Autowired
    private IAsstesSupplierService asstesSupplierService;

    @RequiresPermissions("system:supplier:view")
    @GetMapping()
    public String supplier()
    {
        return prefix + "/supplier";
    }

    /**
     * 查询供应商列表
     */
    @RequiresPermissions("system:supplier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AsstesSupplier asstesSupplier)
    {
        startPage();
        List<AsstesSupplier> list = asstesSupplierService.selectAsstesSupplierList(asstesSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表
     */
    @RequiresPermissions("system:supplier:export")
    @Log(title = "供应商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AsstesSupplier asstesSupplier)
    {
        List<AsstesSupplier> list = asstesSupplierService.selectAsstesSupplierList(asstesSupplier);
        ExcelUtil<AsstesSupplier> util = new ExcelUtil<AsstesSupplier>(AsstesSupplier.class);
        return util.exportExcel(list, "供应商数据");
    }

    /**
     * 新增供应商
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商
     */
    @RequiresPermissions("system:supplier:add")
    @Log(title = "供应商", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AsstesSupplier asstesSupplier)
    {
        return toAjax(asstesSupplierService.insertAsstesSupplier(asstesSupplier));
    }

    /**
     * 修改供应商
     */
    @RequiresPermissions("system:supplier:edit")
    @GetMapping("/edit/{supplierId}")
    public String edit(@PathVariable("supplierId") Long supplierId, ModelMap mmap)
    {
        AsstesSupplier asstesSupplier = asstesSupplierService.selectAsstesSupplierBySupplierId(supplierId);
        mmap.put("asstesSupplier", asstesSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商
     */
    @RequiresPermissions("system:supplier:edit")
    @Log(title = "供应商", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AsstesSupplier asstesSupplier)
    {
        return toAjax(asstesSupplierService.updateAsstesSupplier(asstesSupplier));
    }

    /**
     * 删除供应商
     */
    @RequiresPermissions("system:supplier:remove")
    @Log(title = "供应商", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(asstesSupplierService.deleteAsstesSupplierBySupplierIds(ids));
    }
}
